var reg1 = /0*([1-9]\d*|0\.\d+)/;
var reg2 = /(?:\.0*|(\.\d+?)0+)$/;
function showLoading(content){
	uni.showLoading({
		title : content,
		mask:true
	});
}
function hideLoading(){
	uni.hideLoading();
}
function showToastSuc(content){
	uni.showToast({
		title: content,
		icon: 'success',
		duration: 1800
	})
}
function showToast(content,duration){
	uni.showToast({
		title: content,
		icon: 'none',
		duration: duration == undefined ? 1800 : duration
	})
}
function setClipborarData(content){
	uni.setClipboardData({
		data:content,
		success:()=>{
			uni.showToast({
				title: '复制成功',
				icon: 'success',
				duration: 1800
			})
		}
	})
}
function navigateTo(page){
	uni.navigateTo({
		url: page
	})
}
function comNavigateToLogin(opt,canRefreshFlag){
	uni.navigateTo({
		url:'/pages/login/login?loadOpt=' + opt + '&canRefreshFlag=' + canRefreshFlag
	})
}
function redirectTo(page){
	uni.redirectTo({
		url: page
	})
}
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
}
function patternNum(str){
	if(str != ''){
		str = parseFloat(str.replace(reg1, '$1').replace(reg2, '$1')).toFixed(2);
	}else{
		str = 0;
	}
	return str;
}
function isEmojiCharacter(substring){
	if(substring){
		for ( var i = 0; i < substring.length; i++) {
			var hs = substring.charCodeAt(i);
			if (0xd800 <= hs && hs <= 0xdbff) {
				if (substring.length > 1) {
					var ls = substring.charCodeAt(i + 1);
					var uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
					if (0x1d000 <= uc && uc <= 0x1f77f) {
						return true;
					}
				}
			} else if (substring.length > 1) {
				var ls = substring.charCodeAt(i + 1);
				if (ls == 0x20e3) {
					return true;
				}
			} else {
				if (0x2100 <= hs && hs <= 0x27ff) {
					return true;
				} else if (0x2B05 <= hs && hs <= 0x2b07) {
					return true;
				} else if (0x2934 <= hs && hs <= 0x2935) {
					return true;
				} else if (0x3297 <= hs && hs <= 0x3299) {
					return true;
				} else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030
					|| hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b
					|| hs == 0x2b50) {
					return true;
				}
			}
		}
	}
}

function appendZero(obj){
	if (obj < 10) {
	  return '0' + obj 
	} else {
	  return obj
	} 
}
function getNowTimeDay(){
	var date = new Date();
	return date.getFullYear() + '-' + appendZero((date.getMonth()+1)) + '-' + appendZero(date.getDate());
}
function getNowTimeMonth(){
	var date = new Date();
	return date.getFullYear() + '-' + appendZero((date.getMonth()+1));
}
function getNowTime(){
	let now = new Date();
	let year = now.getFullYear(); //获取完整的年份(4位,1970-????)
	let month = now.getMonth() + 1; //获取当前月份(0-11,0代表1月)
	let today = now.getDate(); //获取当前日(1-31)
	let hour = now.getHours(); //获取当前小时数(0-23)
	let minute = now.getMinutes(); //获取当前分钟数(0-59)
	let second = now.getSeconds(); //获取当前秒数(0-59)
	let nowTime = ''
	nowTime = year + '-' + appendZero(month) + '-' + appendZero(today) + ' ' + appendZero(hour) + ':' +
	  appendZero(minute) + ':' + appendZero(second)
	return nowTime
}
function commonMultiSelect(obj,newObj,index,name){
	if(obj[index].selFlag){
		obj[index].selFlag = false;
		for(var i=0;i<newObj.length;i++){
			if(name == newObj[i]){
				newObj.splice(i,1);
			}
		}
	}else if(obj[index].selFlag == false) {
		obj[index].selFlag = true;
		newObj.push(obj[index].name)
	}
	//console.log(newObj)
}
function replaceToBr(str){
	return str.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
}
function delLastQuot(str){
	return str.substring(0,str.length - 1)
}
function dateToWeek(time){
	const weekNum = new Date(time).getDay();
	let week = '';
	switch (weekNum) {
	    case 0:
	      week = "星期日";
	      break;
	    case 1:
	      week = "星期一";
	      break;
	    case 2:
	      week = "星期二";
	      break;
	    case 3:
	      week = "星期三";
	      break;
	    case 4:
	      week = "星期四";
	      break;
	    case 5:
	      week = "星期五";
	      break;
	    case 6:
	      week = "星期六";
	      break;
	  }
	  return week;
}
export default {
	showLoading,
	hideLoading,
	showToastSuc,
	showToast,
	navigateTo,
	redirectTo,
	trim,
	isEmojiCharacter,
	patternNum,
	setClipborarData,
	comNavigateToLogin,
	commonMultiSelect,
	getNowTime,
	getNowTimeDay,
	getNowTimeMonth,
	replaceToBr,
	delLastQuot,
	dateToWeek
}
